package org.xg.study.pd.event;

import org.xg.study.pd.ICouponDiscount;

import java.math.BigDecimal;

/**
 * @author CMG
 * @version 1.0
 * @description
 * @cLassName ZKCouponDiscount
 * @date 2021/9/18 9:10
 **/
public class ZKCouponDiscount implements ICouponDiscount<Double> {
    /**
     * 折扣计算
     *      * 1. 使用商品价格乘以折扣比例，为最后支付金额
     *      * 2. 保留两位小数
     *      * 3. 最低支付金额1元
     * @param couponInfo 折扣卷信息 ；直减、满减、折扣、N元购
     * @param skuPrice sku金额
     * @return
     */
    @Override
    public BigDecimal discountAmount(Double couponInfo, BigDecimal skuPrice) {
        BigDecimal discountAmount = skuPrice.multiply(new BigDecimal(couponInfo)).setScale(2,BigDecimal.ROUND_HALF_UP);
        if(discountAmount.compareTo(BigDecimal.ZERO)<1){
            return BigDecimal.ZERO;
        }
        return discountAmount;
    }
}
